/**
 * Copyright (c) Software Institude of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.model.uml.Kernel;
// imports:
import org.w3c.dom.Element;

import edu.pku.sei.gefcommon.descriptor.annotation.EnumerationProperty;
import edu.pku.sei.gefcommon.descriptor.annotation.MethodProperty;
import edu.pku.sei.modeler.model.common.MetaTypedList;
import edu.pku.sei.modeler.model.uml.Dependencies.Dependency;
import edu.pku.sei.modeler.model.xml.XMLUtility;
import edu.pku.sei.modeler.uml.modelHelper.ModelPackage;
import edu.pku.sei.modeler.uml.util.MetaTypedSet;


/**
 * @generated
 * modified by zsj
 *
 */
public class NamedElement extends UMLElement implements INamedElement {
	// attributes
	
	protected String name = "";
	
	/**
	 * Determines the visibility of the NamedElement within different Namespaces
	 * within the overall model.
	 */
	protected VisibilityKind visibility;
	
	/**
	 * A name that allows the NamedElement to be identified within a hierarchy
	 * of nested Namespaces. It is constructed from the names of the containing
	 * namespaces starting at the root of the hierarchy and ending with the name
	 * of the NamedElement itself. This is a derived attribute.
	 */
	private String qualifiedName;
	
	
	
	
	// references
	
	protected MetaTypedList supplierDependency;
	
	
	
	// getters & setters for attributes
	
	@MethodProperty(
			id = "NAMEDELEMENT_NAME",
			catalog = "General",
			name = ModelPackage.NAMEDELEMENT_NAME,
			setter = "setName"
			)
	
	public String getName() {
		return name;
	}
	public void setName(String newName) {
		String oldname = name;
		name = newName;
		firePropertyChange(ModelPackage.NAMEDELEMENT_NAME, oldname, newName);
	}
	@MethodProperty(id = "NAMEDELEMENT_VISIBILITY", catalog = "General", name = ModelPackage.NAMEDELEMENT_VISIBILITY, setter = "setVisibility")
	@EnumerationProperty(function = "getAllVisibilityKinds")
	public VisibilityKind getVisibility() {
		return visibility;
	}
	public void setVisibility(VisibilityKind newVisibility) {
		VisibilityKind oldvisibility = visibility;
		visibility = newVisibility;
		firePropertyChange(ModelPackage.NAMEDELEMENT_VISIBILITY, oldvisibility, newVisibility);
	}
	public Object[] getAllVisibilityKinds() {
		return VisibilityKind.getAllVisibilityKinds();
	}
	@MethodProperty(
			id = "NAMEDELEMENT_QUALIFIEDNAME",
			catalog = "General",
			name = ModelPackage.NAMEDELEMENT_QUALIFIEDNAME,
			setter = "setQualifiedName"
			)
	
	public String getQualifiedName() {
		return qualifiedName;
	}
	public void setQualifiedName(String newQualifiedName) {
		String oldqualifiedName = qualifiedName;
		qualifiedName = newQualifiedName;
		firePropertyChange(ModelPackage.NAMEDELEMENT_QUALIFIEDNAME, oldqualifiedName, newQualifiedName);
	}
	
	// getters for references
	
	public MetaTypedList getSupplierDependency() {
		if(supplierDependency == null) {
			supplierDependency = new MetaTypedSet(Dependency.class, this, ModelPackage.NAMEDELEMENT_SUPPLIERDEPENDENCY);
		}
		return supplierDependency;
	}
	
	// save & load
	public void serialize(Element root) {
		super.serialize(root);
		// attributes
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.NAMEDELEMENT_NAME, name);
		
		if (this.visibility != null) {
			XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.NAMEDELEMENT_VISIBILITY, this.visibility.getEnumName());
		}
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.NAMEDELEMENT_QUALIFIEDNAME, qualifiedName);
		
		// references
		
//		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.NAMEDELEMENT_SUPPLIERDEPENDENCY, supplierDependency);		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.NAMEDELEMENT_SUPPLIERDEPENDENCY, supplierDependency);
	}
	
	public void deSerialize(Element root) {
		super.deSerialize(root);
		// attributes
		
		name = XMLUtility.xmlInstance.deSerializeString(root, ModelPackage.NAMEDELEMENT_NAME);
		
		visibility = new VisibilityKind(XMLUtility.xmlInstance.deSerializeString(root, ModelPackage.NAMEDELEMENT_VISIBILITY));
		
		qualifiedName = XMLUtility.xmlInstance.deSerializeString(root, ModelPackage.NAMEDELEMENT_QUALIFIEDNAME);
		
		// references
		
//		this.getSupplierDependency().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.NAMEDELEMENT_SUPPLIERDEPENDENCY, this));
		this.getSupplierDependency().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.NAMEDELEMENT_SUPPLIERDEPENDENCY));
	}
	
	public void dynamicSet(String featureID, Object value) {
		if(featureID == null || "".equals(featureID)) {
			return;
		}
		// attributes
		
		else if(ModelPackage.NAMEDELEMENT_VISIBILITY.equals(featureID)) {
			visibility = (VisibilityKind)value;
		}
		
		// references
		
		else if(ModelPackage.NAMEDELEMENT_SUPPLIERDEPENDENCY.equals(featureID)) {
			getSupplierDependency().add(value);
		}
		
		else
			super.dynamicSet(featureID, value);
	}
	
	public String toString() {
		return this.name;
	}

}
 
 
 
 
 